package vn.intelsoft.vlogvn.adapter;

import java.util.List;


import vn.intelsoft.vlogvn.R;
import vn.intelsoft.vlogvn.imageloader.ImageLoader1;
import vn.intelsoft.vlogvn.instance.Vlogger;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MenuAdapter extends BaseAdapter{
	
	private Context mContext;
	private List<Vlogger> mVloggers;
	private ImageLoader1 imageLoader1;
	
	public MenuAdapter(Context context, List<Vlogger> vloggers) {
		this.mContext = context;
		this.mVloggers = vloggers;
		imageLoader1 = new ImageLoader1(mContext);
	}
	@Override
	public int getCount() {
		return mVloggers.size();
	}

	@Override
	public Object getItem(int position) {
		return mVloggers.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if(convertView == null){
			convertView = LayoutInflater.from(mContext).inflate(R.layout.menu_item, null);
			viewHolder = new ViewHolder();
			viewHolder.imageview1 = (ImageView) convertView.findViewById(R.id.icon);
			viewHolder.textview1 = (TextView) convertView.findViewById(R.id.name);
			
			convertView.setTag(viewHolder);
		}else{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		Vlogger vlogger = mVloggers.get(position);
		
		viewHolder.textview1.setText(vlogger.name);
		imageLoader1.DisplayImage(vlogger.thumb, viewHolder.imageview1);
		
		return convertView;
	}
	
	private class ViewHolder{
		ImageView imageview1;
		TextView textview1;
	}

}
